package ru.mcfr.oxygen.updater;

import javax.swing.JCheckBox;
import javax.swing.JFileChooser;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

@SuppressWarnings("serial")
public abstract class SettingsWindow extends javax.swing.JFrame {
	
	public SettingsWindow() {
		initComponents();
	}

	private void initComponents() {
		urlLabel = new javax.swing.JLabel();
		urlUpdateServer = new javax.swing.JTextField();
		useProxyCheck = new javax.swing.JCheckBox();
		proxyServerLabel = new javax.swing.JLabel();
		proxyServer = new javax.swing.JTextField();
		proxyUserLabel = new javax.swing.JLabel();
		proxyPassLabel = new javax.swing.JLabel();
		proxyUserName = new javax.swing.JTextField();
		showPassCheck = new javax.swing.JCheckBox();
		closeButton = new javax.swing.JButton();
		checkUpdatesButton = new javax.swing.JButton();
		proxyUserPass = new javax.swing.JPasswordField();
		oXygenPathLabel = new javax.swing.JLabel();
		oXygenPath = new javax.swing.JTextField();
		selectPathButton = new javax.swing.JButton();

		setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
		setTitle("Настройки обновлений.");
		setResizable(false);

		urlLabel.setText("URL  сервера обновлений:");

		useProxyCheck.setText("Использовать Прокси-Сервер");

		proxyServerLabel.setText("Сервер:");

		proxyUserLabel.setText("Пользователь:");

		proxyPassLabel.setText("Пароль:");

		showPassCheck.setText("показать текст");
		showPassCheck.addChangeListener(new javax.swing.event.ChangeListener() {
			public void stateChanged(javax.swing.event.ChangeEvent evt) {
				showPassText(evt);
			}
		});
		showPassCheck.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				jCheckBox2ActionPerformed(evt);
			}
		});

		closeButton.setText("Закрыть");
		closeButton.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				jCloseButtonAction(evt);
			}
		});

		checkUpdatesButton.setText("Прверка настроек");
		checkUpdatesButton
				.addActionListener(new java.awt.event.ActionListener() {
					public void actionPerformed(java.awt.event.ActionEvent evt) {
						jCheckUpdatesButtonAction(evt);
					}
				});

		oXygenPathLabel.setText("<oXygen/>:");

		selectPathButton.setText("...");
		selectPathButton.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				jDirectorySelectAction(evt);
			}
		});

		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(
				getContentPane());
		getContentPane().setLayout(layout);
		layout
				.setHorizontalGroup(layout
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								layout
										.createSequentialGroup()
										.addContainerGap()
										.addGroup(
												layout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.LEADING)
														.addGroup(
																layout
																		.createSequentialGroup()
																		.addComponent(
																				urlLabel)
																		.addPreferredGap(
																				javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																		.addComponent(
																				urlUpdateServer,
																				javax.swing.GroupLayout.DEFAULT_SIZE,
																				199,
																				Short.MAX_VALUE))
														.addComponent(
																useProxyCheck)
														.addGroup(
																layout
																		.createSequentialGroup()
																		.addGap(
																				12,
																				12,
																				12)
																		.addGroup(
																				layout
																						.createParallelGroup(
																								javax.swing.GroupLayout.Alignment.LEADING)
																						.addGroup(
																								layout
																										.createSequentialGroup()
																										.addComponent(
																												proxyUserLabel)
																										.addPreferredGap(
																												javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																										.addComponent(
																												proxyUserName,
																												javax.swing.GroupLayout.DEFAULT_SIZE,
																												273,
																												Short.MAX_VALUE))
																						.addGroup(
																								layout
																										.createSequentialGroup()
																										.addComponent(
																												proxyServerLabel)
																										.addPreferredGap(
																												javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																										.addComponent(
																												proxyServer,
																												javax.swing.GroupLayout.DEFAULT_SIZE,
																												321,
																												Short.MAX_VALUE))
																						.addGroup(
																								layout
																										.createSequentialGroup()
																										.addComponent(
																												proxyPassLabel)
																										.addPreferredGap(
																												javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																										.addComponent(
																												proxyUserPass,
																												javax.swing.GroupLayout.PREFERRED_SIZE,
																												182,
																												javax.swing.GroupLayout.PREFERRED_SIZE)
																										.addPreferredGap(
																												javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																										.addComponent(
																												showPassCheck))))
														.addGroup(
																javax.swing.GroupLayout.Alignment.TRAILING,
																layout
																		.createSequentialGroup()
																		.addComponent(
																				checkUpdatesButton)
																		.addPreferredGap(
																				javax.swing.LayoutStyle.ComponentPlacement.RELATED,
																				186,
																				Short.MAX_VALUE)
																		.addComponent(
																				closeButton))
														.addGroup(
																layout
																		.createSequentialGroup()
																		.addComponent(
																				oXygenPathLabel)
																		.addPreferredGap(
																				javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																		.addComponent(
																				oXygenPath,
																				javax.swing.GroupLayout.DEFAULT_SIZE,
																				269,
																				Short.MAX_VALUE)
																		.addPreferredGap(
																				javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																		.addComponent(
																				selectPathButton,
																				javax.swing.GroupLayout.PREFERRED_SIZE,
																				36,
																				javax.swing.GroupLayout.PREFERRED_SIZE)))
										.addContainerGap()));
		layout
				.setVerticalGroup(layout
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								javax.swing.GroupLayout.Alignment.TRAILING,
								layout
										.createSequentialGroup()
										.addContainerGap(
												javax.swing.GroupLayout.DEFAULT_SIZE,
												Short.MAX_VALUE)
										.addGroup(
												layout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.BASELINE)
														.addComponent(
																oXygenPathLabel)
														.addComponent(
																oXygenPath,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE)
														.addComponent(
																selectPathButton))
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.RELATED)
										.addGroup(
												layout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.BASELINE)
														.addComponent(urlLabel)
														.addComponent(
																urlUpdateServer,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE))
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
										.addComponent(useProxyCheck)
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.RELATED)
										.addGroup(
												layout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.BASELINE)
														.addComponent(
																proxyServerLabel)
														.addComponent(
																proxyServer,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE))
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.RELATED)
										.addGroup(
												layout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.BASELINE)
														.addComponent(
																proxyUserLabel)
														.addComponent(
																proxyUserName,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE))
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.RELATED)
										.addGroup(
												layout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.BASELINE)
														.addComponent(
																proxyPassLabel)
														.addComponent(
																showPassCheck)
														.addComponent(
																proxyUserPass,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE))
										.addGap(18, 18, 18)
										.addGroup(
												layout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.BASELINE)
														.addComponent(
																closeButton)
														.addComponent(
																checkUpdatesButton))
										.addGap(27, 27, 27)));
		
		pack();
	}// </editor-fold>

	protected abstract void jCloseButtonAction(java.awt.event.ActionEvent evt);

	protected abstract void jCheckUpdatesButtonAction(java.awt.event.ActionEvent evt);

	private void jCheckBox2ActionPerformed(java.awt.event.ActionEvent evt) {
	}

	private void showPassText(javax.swing.event.ChangeEvent evt) {
		JCheckBox jcb = (JCheckBox) evt.getSource();
		if (jcb.isSelected()) {
			proxyUserPass.setEchoChar((char) 0);
		} else {
			proxyUserPass.setEchoChar('*');
		}
	}

	private void jDirectorySelectAction(java.awt.event.ActionEvent evt) {
		final JFileChooser fc = new JFileChooser();
        fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        fc.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent actionEvent) {
                if (actionEvent.getActionCommand().equalsIgnoreCase(JFileChooser.APPROVE_SELECTION))
                    oXygenPath.setText(fc.getSelectedFile().getAbsolutePath());
            }
        });
        fc.showOpenDialog(this);
	}
	
	private javax.swing.JButton closeButton;
	private javax.swing.JButton selectPathButton;
	private javax.swing.JCheckBox showPassCheck;
	private javax.swing.JLabel urlLabel;
	private javax.swing.JLabel proxyServerLabel;
	private javax.swing.JLabel proxyUserLabel;
	private javax.swing.JLabel proxyPassLabel;
	private javax.swing.JLabel oXygenPathLabel;
	
	protected javax.swing.JButton checkUpdatesButton;
	protected javax.swing.JCheckBox useProxyCheck;
	protected javax.swing.JPasswordField proxyUserPass;
	protected javax.swing.JTextField urlUpdateServer;
	protected javax.swing.JTextField proxyServer;
	protected javax.swing.JTextField proxyUserName;
	protected javax.swing.JTextField oXygenPath;

}
